package com.leetcode.offer.chapter2;

/**
 * @author Dennis Li
 * @date 2020/7/11 22:26
 */
public class SpinArray_11 {

    public static void main(String[] args) {
        System.out.println(new SpinArray_11().minArray(new int[]{3, 4, 5, 1, 2}));
    }

    public int minArray(int[] numbers) {
        for (int i = 0, j = numbers.length - 1; i < j; i++, j--) {
            if (numbers[i] > numbers[i + 1]) {
                return numbers[i + 1];
            } else if (numbers[j] < numbers[j - 1]) {
                return numbers[j];
            }
        }
        return 0;
    }
}
